﻿#region | Copyright © Siriwat Suananpornpanit 2556 |

/*
	##########################################################################
		Software Generator Code For Hashtable From Table Name => FUNCTION_GROUP
		Author By : Siriwat Suananpornpanit
		DateTime : 2556/08/22 12:00:25
	##########################################################################
	*/

#endregion

#region Class | Imports |

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using DataAccess.Interface;
using Microsoft.VisualBasic;
using System.Text;
using DataAccess.DBConnections;
using DataAccess.ProxyConnections;
using Oracle.DataAccess.Client;

#endregion

namespace DataAccess.Dal
{
    internal class FunctionGroupDal //: IResponsible<Prop.FunctionGroup>
    {

        /* for DataBase Connection */

        private static DBConnectionsEngine dbEngine;

        private static OracleConnection Conn;

        private static Hashtable hashtable;


        private static FunctionGroupDal _dal;

        private System.String sql = "";


        public static FunctionGroupDal GetInstance()
        {
            /* for Init */

            dbEngine = new DBConnectionsEngine();

            Conn = new DatabaseProxy().GetAuthConnection();

            _dal = new FunctionGroupDal();

            return _dal;
        }

        public IEnumerable<Prop.FunctionGroup> Select(Prop.FunctionGroup obj)
        {
            IEnumerable<Prop.FunctionGroup> entities = new List<Prop.FunctionGroup>();
            try
            {
                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.IS_CENTER))
                    {
                        concast.Append(" AND IS_CENTER=:IS_CENTER ");
                        hashtable.Add(":IS_CENTER", obj.IS_CENTER);
                    }

                    if (!String.IsNullOrEmpty(obj.REMARK))
                    {
                        concast.Append(" AND REMARK=:REMARK ");
                        hashtable.Add(":REMARK", obj.REMARK);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.CRBY))
                    {
                        concast.Append(" AND CRBY=:CRBY ");
                        hashtable.Add(":CRBY", obj.CRBY);
                    }

                    if (!Information.IsDate(obj.UPDDATE))
                    {
                        concast.Append(" AND UPDDATE=:UPDDATE ");
                        hashtable.Add(":UPDDATE", obj.UPDDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.UPDBY))
                    {
                        concast.Append(" AND UPDBY=:UPDBY ");
                        hashtable.Add(":UPDBY", obj.UPDBY);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.GROUPNO))
                    {
                        concast.Append(" AND GROUPNO=:GROUPNO ");
                        hashtable.Add(":GROUPNO", obj.GROUPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.GROUPDESC))
                    {
                        concast.Append(" AND GROUPDESC=:GROUPDESC ");
                        hashtable.Add(":GROUPDESC", obj.GROUPDESC);
                    }

                }
                sql = System.String.Format(@" SELECT COMPANY_CODE ,IS_CENTER ,REMARK ,CRDATE ,CRBY ,UPDDATE ,UPDBY ,APPLNO ,GROUPNO ,GROUPDESC  FROM FUNCTION_GROUP");

                sql = sql + concast.ToString();

                entities = dbEngine.ToList<Prop.FunctionGroup>(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                entities = null;
            }
            return entities;
        }

        public Boolean Add(Prop.FunctionGroup obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" INSERT INTO FUNCTION_GROUP(COMPANY_CODE ,IS_CENTER ,REMARK ,CRDATE ,CRBY ,UPDDATE ,UPDBY ,APPLNO ,GROUPNO ,GROUPDESC )
					VALUES(:COMPANY_CODE ,:IS_CENTER ,:REMARK ,:CRDATE ,:CRBY ,:UPDDATE ,:UPDBY ,:APPLNO ,:GROUPNO ,:GROUPDESC ");

                hashtable = new Hashtable();
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":IS_CENTER", obj.IS_CENTER);
                hashtable.Add(":REMARK", obj.REMARK);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":CRBY", obj.CRBY);
                hashtable.Add(":UPDDATE", obj.UPDDATE);
                hashtable.Add(":UPDBY", obj.UPDBY);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":GROUPNO", obj.GROUPNO);
                hashtable.Add(":GROUPDESC", obj.GROUPDESC);
                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Update(Prop.FunctionGroup obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" UPDATE FUNCTION_GROUP
					SET
					COMPANY_CODE=:COMPANY_CODE,
					IS_CENTER=:IS_CENTER,
					REMARK=:REMARK,
					CRDATE=:CRDATE,
					CRBY=:CRBY,
					UPDDATE=:UPDDATE,
					UPDBY=:UPDBY,
					APPLNO=:APPLNO,
					GROUPNO=:GROUPNO,
					GROUPDESC=:GROUPDESC");

                hashtable = new Hashtable();
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":IS_CENTER", obj.IS_CENTER);
                hashtable.Add(":REMARK", obj.REMARK);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":CRBY", obj.CRBY);
                hashtable.Add(":UPDDATE", obj.UPDDATE);
                hashtable.Add(":UPDBY", obj.UPDBY);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":GROUPNO", obj.GROUPNO);
                hashtable.Add(":GROUPDESC", obj.GROUPDESC);

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Delete(Prop.FunctionGroup obj)
        {
            Boolean result = false;
            try
            {

                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.IS_CENTER))
                    {
                        concast.Append(" AND IS_CENTER=:IS_CENTER ");
                        hashtable.Add(":IS_CENTER", obj.IS_CENTER);
                    }

                    if (!String.IsNullOrEmpty(obj.REMARK))
                    {
                        concast.Append(" AND REMARK=:REMARK ");
                        hashtable.Add(":REMARK", obj.REMARK);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.CRBY))
                    {
                        concast.Append(" AND CRBY=:CRBY ");
                        hashtable.Add(":CRBY", obj.CRBY);
                    }

                    if (!Information.IsDate(obj.UPDDATE))
                    {
                        concast.Append(" AND UPDDATE=:UPDDATE ");
                        hashtable.Add(":UPDDATE", obj.UPDDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.UPDBY))
                    {
                        concast.Append(" AND UPDBY=:UPDBY ");
                        hashtable.Add(":UPDBY", obj.UPDBY);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.GROUPNO))
                    {
                        concast.Append(" AND GROUPNO=:GROUPNO ");
                        hashtable.Add(":GROUPNO", obj.GROUPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.GROUPDESC))
                    {
                        concast.Append(" AND GROUPDESC=:GROUPDESC ");
                        hashtable.Add(":GROUPDESC", obj.GROUPDESC);
                    }

                }
                sql = System.String.Format(@" DELETE FROM FUNCTION_GROUP ");

                sql = sql + concast.ToString();

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

    }
}

/*
##########################################################################
    Free Software License
##########################################################################
*/

